/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.google.code.jmarias.client.components;

import com.google.code.jmarias.client.Globals;
import com.google.code.jmarias.client.GameLocals;
import com.google.code.jmarias.client.phases.*;
import com.google.code.jmarias.common.Suit;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import org.newdawn.slick.Color;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.geom.Vector2f;
import org.newdawn.slick.state.StateBasedGame;

/**
 *
 * @author bart
 */
public class PrintInfoComponent extends AbstractRenderComponent {
    private Globals global;
    private GameLocals locals;

    private Image trumpInfo = null;
    private ArrayList<Image> trumpImages = new ArrayList<Image>();

    private Image waitImage = null;


    private Map<Class, String> phaseInfo = new HashMap<Class, String>() {
      {
        put(PickTrumpPhase.class, "Zvol trumfovou barvu.");
        put(DropTalonPhase.class, "Odhod talon.");
        put(ChooseFromPeoplePhase.class, "Vyber z lidu jednu kartu.");
        put(AskForChoicePhase.class, "Co chceš hrát?");
      }
    };

    public PrintInfoComponent(int id, Globals global, GameLocals locals) throws SlickException {
        super(id);

        this.global = global;
        this.locals = locals;

        trumpInfo = new Image(global.getIMGPATH() + "ukazateleHry.png");
        // Srdce
        trumpImages.add(trumpInfo.getSubImage(0, 0, 100, 41));
        // Kule
        trumpImages.add(trumpInfo.getSubImage(0, 41, 100, 41));
        // Zelene
        trumpImages.add(trumpInfo.getSubImage(0, 82, 100, 41));
        // Zaludy
        trumpImages.add(trumpInfo.getSubImage(0, 123, 100, 41));

        waitImage= new Image(global.getIMGPATH() + "cekaci2.png");
    }


    @Override
    public void update(GameContainer gc, StateBasedGame sb, int delta) {
    }

    @Override
    public void render(GameContainer gc, StateBasedGame sb, Graphics gr) {

        // Informacni tabulka se zvolenym trumfem
        if(locals.getTrumpCard() != null) {
            if(locals.getTrumpCard().getSuit() == Suit.hearts)
                    trumpImages.get(0).draw(0f, global.getScreenHeight() - trumpImages.get(0).getHeight() , 1.0f);
            else if(locals.getTrumpCard().getSuit() == Suit.bells)
                    trumpImages.get(1).draw(0f, global.getScreenHeight() - trumpImages.get(0).getHeight() , 1.0f);
            else if(locals.getTrumpCard().getSuit() ==  Suit.leaves)
                    trumpImages.get(2).draw(0f, global.getScreenHeight() - trumpImages.get(0).getHeight() , 1.0f);
            else if(locals.getTrumpCard().getSuit() == Suit.acorns) {
                    trumpImages.get(3).draw(0f, global.getScreenHeight() - trumpImages.get(0).getHeight() , 1.0f);
            }

            global.printText("small", new Vector2f(0f, global.getScreenHeight()), Color.black, "trumf:" + locals.getTrumpCard().toString() + (global.getScreenHeight() - trumpImages.get(0).getHeight()), "bottom", "left");
        }

        // Pokyny k aktualni fazi hry
        if (locals.getCurrentPhase() != null && phaseInfo.get(locals.getCurrentPhase().getClass()) != null) {
                global.printText("normal", new Vector2f(global.getScreenWidth()/2f, global.getScreenHeight()), Color.white, phaseInfo.get(locals.getCurrentPhase().getClass()), "bottom", "center");
        }

        // Cekaci ikonka u jednotlivych hracu
        if(locals.getWait() != 0) {
            if(locals.getWait() == 1) {
                waitImage.draw(50f, 50f, 1.0f);
            } else if(locals.getWait() == 2) {
                waitImage.draw(global.getScreenWidth() - waitImage.getWidth() - 50f, 50f, 1.0f);
            }
        }


    }

}
